package com.nanhai.buddhist.college.module.collegebase.dal.mysql.studentchange;

import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.mybatis.core.mapper.BaseMapperX;
import com.nanhai.buddhist.college.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.nanhai.buddhist.college.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.studentchange.vo.StudentChangeExportReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.studentchange.vo.StudentChangePageReqVO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.classes.ClassesDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.departments.DepartmentsDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.professions.ProfessionsDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.studentchange.StudentChangeDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.studentroll.StudentRollDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 学籍信息异动 Mapper
 *
 * @author Akai
 */
@Mapper
public interface StudentChangeMapper extends BaseMapperX<StudentChangeDO> {

    default PageResult<StudentChangeDO> selectPage(StudentChangePageReqVO reqVO) {
        return selectPageForJoin(reqVO,StudentChangeDO.class, new MPJLambdaWrapperX<StudentChangeDO>()
                .eqIfPresent(StudentChangeDO::getChangeNumber, reqVO.getChangeNumber())
                .likeIfPresent(StudentRollDO::getStudentName, reqVO.getStudentName())
                .eqIfPresent(StudentChangeDO::getChangeType, reqVO.getChangeType())
                .eqIfPresent(StudentChangeDO::getCheckStatus, reqVO.getCheckStatus())
                .betweenIfPresent(StudentChangeDO::getCreateTime, reqVO.getCreateTime())
                .betweenIfPresent(StudentChangeDO::getChangeTime, reqVO.getChangeTime())
                .geIfPresent(StudentChangeDO::getChangeTime,reqVO.getChangeStartTimeDate())
                .leIfPresent(StudentChangeDO::getChangeTime,reqVO.getChangeEndTimeDate())
                .leftJoin(StudentRollDO.class,StudentRollDO::getId,StudentChangeDO::getStudentId)
                .leftJoin(DepartmentsDO.class,DepartmentsDO::getId, StudentChangeDO::getNewDepartment)
                .leftJoin(ClassesDO.class,ClassesDO::getId, StudentChangeDO::getNewClassGrade)
                .leftJoin(ProfessionsDO.class,ProfessionsDO::getId, StudentChangeDO::getNewMajor)

                .selectAs(DepartmentsDO::getDepartmentName,StudentChangeDO::getDepartmentName)
                .selectAs(ClassesDO::getClassesName,StudentChangeDO::getClassesName)
                .selectAs(ProfessionsDO::getProfessionName,StudentChangeDO::getProfessionName)
                .selectAll(StudentChangeDO.class)
                .selectAs(StudentRollDO::getStudentName,StudentChangeDO::getStudentName)
                .selectAs(StudentRollDO::getStudentNumber,StudentChangeDO::getStudentNumber)
                .selectAs(StudentRollDO::getLegalName,StudentChangeDO::getLegalName)
                .orderByDesc(StudentChangeDO::getCreateTime));
    }

    default List<StudentChangeDO> selectList(StudentChangeExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<StudentChangeDO>()
                .eqIfPresent(StudentChangeDO::getChangeNumber, reqVO.getChangeNumber())
                .eqIfPresent(StudentChangeDO::getStudentId, reqVO.getStudentId())
                .eqIfPresent(StudentChangeDO::getChangeType, reqVO.getChangeType())
                .eqIfPresent(StudentChangeDO::getCheckStatus, reqVO.getCheckStatus())
                .betweenIfPresent(StudentChangeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StudentChangeDO::getCreateTime));
    }

}
